﻿//这个类主要用于太极图形绘制
//author 夏天的树人
//vesion 1.0
package org.summerTree.graphics
{
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.display.Graphics;
	import flash.geom.Point;
	 
	public class TaiJi extends Base
	{
		private var shape:Sprite=new Sprite();
		private var contain:Sprite=new Sprite();
		private var shape2:Sprite=new Sprite();
		private var shape3:Sprite=new Sprite();
		private var R:int;//半径
		private var startX:Number=0;
		private var startY:Number=0;
		public function TaiJi(R:int)
		{
			this.R=R;		
			addChild(shape);
			shape.x=startX;
			shape.y=startY;
			addChild(shape2);
			addChild(shape3);
			creatSprite();
		}
		private function creatSprite():void
		{
			pie(shape.graphics,90,270,R,0x000000);////绘制扇形左边
			pie(shape.graphics,270,450,R,0xffffff);//绘制扇形右边

			shape2.graphics.beginFill(0xffffff);//绘制下圆
			shape2.graphics.drawCircle(startX,startY+R/2,R/2);
			shape2.graphics.endFill();
			
			shape2.graphics.beginFill(0x000000);//绘制上圆
			shape2.graphics.drawCircle(startX,startY-R/2,R/2);
			shape2.graphics.endFill();

			shape3.graphics.beginFill(0xffffff);
			shape3.graphics.drawCircle(startX,startY-R/2,R/4);
			shape3.graphics.endFill();

			shape3.graphics.beginFill(0x000000);
			shape3.graphics.drawCircle(startX,startY+R/2,R/4);
			shape3.graphics.endFill();

		}
		//绘制扇形
		private function pie(g:Graphics,startAngle:Number,endAngle:Number,radius:Number,color:uint):void
		{
			g.lineStyle(1);
			g.moveTo(0,0);
			g.beginFill(color);
			for (var i:Number=startAngle; i<=endAngle; i++)
			{
				var angle:Number = i*Math.PI/180;
				var pointX:Number=Math.cos(angle)*radius;
				var pointY:Number=Math.sin(angle)*radius;
				g.lineTo(pointX, pointY);
			}
			g.lineTo(0,0);
			g.endFill();
		}
		
		override public function clear():void
		{		
			shape.graphics.clear();
			shape2.graphics.clear();
			shape3.graphics.clear();
		}
		
		////设置坐标
//		public function move(x:Number,y:Number):void
//		{			
//			this.x=x;
//			this.y=y;
//		}
		
	}
}